package org.deng.vertx.web.verticle;

import org.deng.vertx.web.dao.MySqlDao;
import org.deng.vertx.web.dao.UserDao;
import org.deng.vertx.web.entity.User;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.json.Json;
import lombok.extern.slf4j.Slf4j;


/**
 * @Author: DengLibin
 * @Date: Create in 2022-04-29 16:52:16
 * @Description: 数据库访问
 */
@Slf4j
public class DaoVerticle extends AbstractVerticle {
  

    @Override
    public void start() throws Exception {
        log.info("DaoVerticle start");
        MySqlDao.getInstance().initMysql(vertx);
    
        //接收消息
        vertx.eventBus().consumer("userDao::insert", msg->{
            User u = Json.decodeValue(msg.body().toString(),User.class);
            UserDao dao = UserDao.getInstance();
            dao.insert(u, r ->{
                //发送消息
                msg.reply(Json.encode(r));
            });
        });
    }
}
